from pages.basePage4 import BasePage
from config.setting import host_port
from selenium.webdriver.common.action_chains import ActionChains
import time
# 元素定位层
class OrderPages(BasePage):
    def __init__(self):
        BasePage.__init__(self)
        time.sleep(2)
        self.driver.get(f"http://{host_port}/SharedParkingPlace/admin/index.html")

    # 定位审核管理
    def examine(self):
        return self.driver.find_element_by_xpath('//div[@id="sm"]/div/div[2]')
    # 定位用户管理
    def user(self):
        return self.driver.find_element_by_xpath('//div[@id="sm"]/div/div[3]')
    # 定位订单管理
    def order_management(self):
        return self.driver.find_element_by_xpath('//div[@id="sm"]/div/div[4]')
    # 定位评价管理
    def evaluate(self):
        return self.driver.find_element_by_id('_easyui_tree_14')
    # 定位表单
    def iframe(self):
        return self.driver.find_element_by_id('testIframe')
    # 定位选择评论
    def Check(self):
        return self.driver.find_element_by_id('datagrid-row-r1-2-0')
    # 定位删除按钮
    def deleted(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[1]')
    #定位评论时间
    def remakertime(self):
        return self.driver.find_element_by_xpath('//*[@id="datagrid-row-r1-2-0"]/td[6]/div')
#    定位评论内容
    def comment_text(self):
        return self.driver.find_element_by_xpath('//*[@id="datagrid-row-r1-2-0"]/td[5]/div')
    # 定位修改按钮
    def mondfiy_com(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[2]/span')
    # 定位评论分数
    def score(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input3"]')
    # 定位修改评论内容
    def mfcomment(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input4"]')
    # 定位修改按钮
    def button(self):
        return self.driver.find_element_by_xpath('//*[@id="dlg-buttons"]/a[2]/span/span[1]')
#     定位评论筛选条件
    def screen(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/span/a')
#     定位评论内容选项
    def screen_text(self):
        return self.driver.find_element_by_xpath('//div[@id="mm"]/div[5]/div')
#   定位查询输入框
    def query_input(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input5"]')
#    定位查询按钮
    def query_button(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/span/span/a')

# 操作层
class OrderHandle(OrderPages):
    def __init__(self):
        OrderPages.__init__(self)

    # 点击审核管理
    def clk_examine(self):
        self.examine().click()
#    点击用户管理
    def clk_user(self):
        self.user().click()
    # 点击订单管理
    def clk_order(self):
        self.order_management().click()
    # 点击评价管理
    def clk_evaluate(self):
        self.evaluate().click()
    # 切换表单
    def  swith_frame(self):
        a =self.iframe()
        return self.driver.switch_to.frame(a)
    # 获取评论时间
    def get_time(self):
        time = self.remakertime().text
        return time
    # 获取评论内容
    def get_text(self):
        text =self.comment_text().text
        return  text
    # 点击评论
    def clk_check(self):
        self.Check().click()
    #点击删除
    def clk_del(self):
        self.deleted().click()
#    点击修改按钮
    def clk_md(self):
        self.mondfiy_com().click()
#     修改评论分数
    def send_score(self,score):
        input1=self.score()
        input1.clear()
        input1.send_keys(score)
    # 修改评论内容
    def send_mf(self,content):
        input2=self.mfcomment()
        input2.clear()
        input2.send_keys(content)
    # 点击修改按钮
    def clk_button(self):
        self.button().click()
#     鼠标悬停于筛选条件
    def get_screen(self):
        a =self.screen()
        ActionChains(self.driver).move_to_element(a).perform()
    # 点击按内容筛选
    def clk_screen(self):
        self.screen_text().click()
    # 输入筛选内容
    def send_query(self,content2):
        self.query_input().send_keys(content2)
    # 点击查询按钮
    def clk_query_button(self):
        self.query_button().click()

# 业务层
class OrderBusiness(OrderHandle):
    def __init__(self):
        OrderHandle.__init__(self)
    # 删除
    def del_order(self):
       self.clk_examine()
       self.clk_user()
       self.clk_order()
       self.clk_evaluate()
       self.swith_frame()
       time.sleep(2)
       time1=self.get_time()
       self.clk_check()
       self.clk_del()
       time.sleep(2)
       time2=self.get_time()
       return time1,time2
#     修改
    def mondfiy_comment(self,score,content,content2):
        self.clk_examine()
        self.clk_user()
        self.clk_order()
        self.clk_evaluate()
        self.swith_frame()
        time.sleep(2)
        self.clk_check()
        self.clk_md()
        self.send_score(score)
        self.send_mf(content)
        self.clk_button()
        time.sleep(2)
        self.get_screen()
        self.clk_screen()
        self.send_query(content2)
        self.clk_query_button()
        return self.get_text()
if __name__ == '__main__':
    o=OrderBusiness()
    r=o.mondfiy_comment(99,'我真的太难了','太难了')
    print(r)

